﻿#region Copyright
//————————————————————————————————————————//
//	创建人员(Creator)    ：Huangyd
//	创建日期(Date)       ：2012-08-05
//  联系方式(Email)      ：aj-ayumi@163.com; gajayumi@gmail.com; ajayumi@me.com
//  描    述(Description)：
//
//	Copyright (C) 2012 ajayumi 版权所有
//————————————————————————————————————————//
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ajayumi.Platform.WinForm.WorkSpace
{
    /// <summary>
    /// 工作空间操作集合
    /// </summary>
    public abstract class WorkSpaces
    {
        //private static WorkSpaces m_Instance;
        //public static WorkSpaces Instance
        //{
        //    get
        //    {
        //        if (m_Instance == null)
        //        {
        //            m_Instance = new WorkSpaces();
        //        }
        //        return m_Instance;

        //    }
        //}

        public WorkSpaceCollection Collection { get; private set; }

        /// <summary>
        /// 获取当前 WorkSpace
        /// </summary>
        public WorkSpaceBase CurrentWorkSpaceBase { get; set; }

        protected WorkSpaces()
        {
            this.Collection = new WorkSpaceCollection();
            this.CurrentWorkSpaceBase = null;
        }

        public event EventHandler WorkSpaceChanged;
        protected void RaiseWorkSpaceChanged()
        {
            if (this.WorkSpaceChanged != null)
            { this.WorkSpaceChanged(this, EventArgs.Empty); }
        }

        ///// <summary>
        ///// 获取当前 WorkSpace
        ///// </summary>
        //public WorkSpaceBase CurrentWorkSpace
        //{
        //    get { return this.CurrentWorkSpaceBase; }
        //}

        /// <summary>
        /// 添加 WorkSpace
        /// </summary>
        /// <param name="item"></param>
        public void Add(WorkSpaceBase item)
        {
            this.Collection.Add(item);
            RaiseWorkSpaceChanged();
        }

        /// <summary>
        /// 根据名称获取 WorkSpace
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        internal WorkSpaceBase GetItem(string name)
        {
            return this.Collection[name];
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parent"></param>
        /// <param name="container"></param>
        public abstract void ShowModule(string name, IParentContainer parent);

        /// <summary>
        /// 移除工作空间对象
        /// </summary>
        /// <param name="name"></param>
        public void Remove(string name)
        {
            if (this.CurrentWorkSpaceBase.IsDisposeControl)
            {
                this.Collection.Remove(name);
            }
            this.CurrentWorkSpaceBase = null;
        }

    }
}
